import bannerService from '../../services/banner'
import * as types from '../mutation-types'
// initial state
const state = {
  nativeSelect: [],
  positionSelect: [],

}

// getters
const getters = {

}

// actions
const actions = {
  loadNativeSelect({commit}) {
    if(state.nativeSelect.length===0){
      bannerService.loadNativeSelectServer(function(data){
        commit(types.LOAD_NATIVE_SELECT,data)
      });
    }
  },
  loadPositionSelect({commit}){
    if(state.positionSelect.length===0) {
      bannerService.publishBannerPositionServer(function (data) {
        commit(types.LOAD_POSITION_SELECT, data)
      });
    }
  }
}

// mutations
const mutations = {
  [types.LOAD_NATIVE_SELECT] (state, data) {
    state.nativeSelect = data.data;
  },
  [types.LOAD_POSITION_SELECT] (state, data) {
    state.positionSelect = data.data;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
